import { defineStore } from 'pinia'
import { MenuService, MFunction } from '@/modules/permission'
import { generateRoutes } from '@/router'
import { RouteRecordRaw } from 'vue-router'

export const routerStore = defineStore('routerStore', {
	state: () => ({
		menuRoutes: [] as RouteRecordRaw[],
		routes: [] as RouteRecordRaw[]
	}),
	actions: {
		async getMenuRoutes() {
			let menus = await MenuService.getMenuList(true)
			const routes = generateRoutes(menus.filter(f => f.parentId == -1))
			//可判断是否用于左侧菜单(菜单组或菜单页面)
			this.menuRoutes.push(...routes)
			return routes
			// this.menuRoutes.push(...routes)
			// return this.menuRoutes
		},
		setRoutes(routers: RouteRecordRaw[]) {
			this.routes = routers
		},
		logoutAction() {
			this.menuRoutes = []
			this.routes = []
		}
	}
})
